﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using CommunitySystem.Assert;
using CommunitySystem.Ctrls;
using CommunitySystem.PublicOfficialSelectionService;
using CommunitySystem.Views;
using EHR.Common;
using org.in2bits.MyXls;

namespace CommunitySystem
{
    public partial class ZhiWeiShiJianAnPaiControl1 : AsyncCtrl, IReturnListenerc
    {
        #region IReturnListenerc 成员
        public void BeginReturn()
        {
            //Load();
        }
        #endregion
        public NavMoveSwitch Nav { get; set; }
        private PublicOfficialSelectionService.PublicOfficialSelectionServiceClient Client1 =
            new PublicOfficialSelectionService.PublicOfficialSelectionServiceClient();

        private ObservableCollection<PublicOfficialRecordModel> models =
            new ObservableCollection<PublicOfficialRecordModel>();
        Dictionary<string,bool> liststring = new Dictionary<string,bool>();
        private string FBType = "选调交流";
        public ZhiWeiShiJianAnPaiControl1(int year, string FaBuType)
        {
            InitializeComponent();
            FBType = FaBuType;
            liststring.Add("面试日期", true);
            liststring.Add("场次", true);
            liststring.Add("面试时间", true);
            liststring.Add("招录单位", true);
            liststring.Add("报考职位", true);
            liststring.Add("姓名", true);
            if (FaBuType == "选调交流")
            {
                this.DGRole.Columns[7].Visibility = System.Windows.Visibility.Collapsed;
            }
            else
            {
                this.DGRole.Columns[7].Visibility = System.Windows.Visibility.Visible;
                liststring.Add("笔试分数", true);
            }

            liststring.Add("身份证号", true);
            liststring.Add("现任单位", true);
            liststring.Add("现任职务", true);
            liststring.Add("现任职务层次", true);

            liststring.Add("现任职务层次时间", true);
            liststring.Add("职务属性", true);
            liststring.Add("性别", true);
            liststring.Add("出生日期", true);
            liststring.Add("政治面貌", true);
            liststring.Add("民族", true);
            liststring.Add("本科毕业院校", true);
            liststring.Add("本科专业", true);
            liststring.Add("硕士毕业院校", true);
            liststring.Add("硕士专业", true);
            liststring.Add("博士毕业院校", true);
            liststring.Add("博士专业", true);

            liststring.Add("学历", true);
            liststring.Add("学位", true);
            liststring.Add("联系方式/手机号码", true);
            liststring.Add("电子邮箱", true);
            liststring.Add("健康程度", true);
            liststring.Add("婚姻状况", true);
            liststring.Add("通讯地址", true);
            Client1.GetExcelFileCompleted += new EventHandler<GetExcelFileCompletedEventArgs>(Client1_GetExcelFileCompleted);
            LoadListBox();
            Load(year, FaBuType);
        }

        private void LoadListBox()
        {
            foreach (string i in liststring.Keys)
            {
                CheckBox cbMonth = new CheckBox();
                cbMonth.Content = i;
                cbMonth.IsChecked = true;
                cbMonth.Checked += new RoutedEventHandler(cbMonth_Checked);
                cbMonth.Unchecked += new RoutedEventHandler(cbMonth_UnChecked);
                ListBoxOfLife.Items.Add(cbMonth);
            }

        }

        private void cbMonth_Checked(object sender, RoutedEventArgs e)
        {
            if (FBType == "选调交流")
            {
                this.DGRole.Columns[7].Visibility = System.Windows.Visibility.Collapsed;
                switch (((CheckBox)sender).Content.ToString())
                {
                    case "面试日期":
                        this.DGRole.Columns[1].Visibility = System.Windows.Visibility.Visible;
                        liststring["面试日期"] = true;
                        break;
                    case "场次":
                        this.DGRole.Columns[2].Visibility = System.Windows.Visibility.Visible;
                        liststring["场次"] = true;
                        break;
                    case "面试时间":
                        this.DGRole.Columns[3].Visibility = System.Windows.Visibility.Visible;
                        liststring["面试时间"] = true;
                        break;
                    case "招录单位":
                        this.DGRole.Columns[4].Visibility = System.Windows.Visibility.Visible;
                        liststring["招录单位"] = true;
                        break;
                    case "报考职位":
                        this.DGRole.Columns[5].Visibility = System.Windows.Visibility.Visible;
                        liststring["报考职位"] = true;
                        break;
                    case "姓名":
                        this.DGRole.Columns[6].Visibility = System.Windows.Visibility.Visible;
                        liststring["姓名"] = true;
                        break;
                    //case "笔试分数":
                    //    this.DGRole.Columns[7].Visibility = System.Windows.Visibility.Visible;
                    //    liststring["笔试分数"] = true;
                    //    break;

                    case "身份证号":
                        this.DGRole.Columns[8].Visibility = System.Windows.Visibility.Visible;
                        liststring["身份证号"] = true;
                        break;
                    case "现任单位":
                        this.DGRole.Columns[9].Visibility = System.Windows.Visibility.Visible;
                        liststring["现任单位"] = true;
                        break;
                    case "现任职务":
                        this.DGRole.Columns[10].Visibility = System.Windows.Visibility.Visible;
                        liststring["现任职务"] = true;
                        break;
                    case "现任职务层次":
                        this.DGRole.Columns[11].Visibility = System.Windows.Visibility.Visible;
                        liststring["现任职务层次"] = true;
                        break;
                    case "现任职务层次时间":
                        this.DGRole.Columns[12].Visibility = System.Windows.Visibility.Visible;
                        liststring["现任职务层次时间"] = true;
                        break;
                    case "性别":
                        this.DGRole.Columns[13].Visibility = System.Windows.Visibility.Visible;
                        liststring["性别"] = true;
                        break;
                    case "出生日期":
                        this.DGRole.Columns[14].Visibility = System.Windows.Visibility.Visible;
                        liststring["出生日期"] = true;
                        break;

                    case "政治面貌":
                        this.DGRole.Columns[15].Visibility = System.Windows.Visibility.Visible;
                        liststring["政治面貌"] = true;
                        break;
                    case "民族":
                        this.DGRole.Columns[16].Visibility = System.Windows.Visibility.Visible;
                        liststring["民族"] = true;
                        break;
                    case "本科毕业院校":
                        this.DGRole.Columns[17].Visibility = System.Windows.Visibility.Visible;
                        liststring["本科毕业院校"] = true;
                        break;
                    case "本科专业":
                        this.DGRole.Columns[18].Visibility = System.Windows.Visibility.Visible;
                        liststring["本科专业"] = true;
                        break;
                    case "硕士毕业院校":
                        this.DGRole.Columns[19].Visibility = System.Windows.Visibility.Visible;
                        liststring["硕士毕业院校"] = true;
                        break;
                    case "硕士专业":
                        this.DGRole.Columns[20].Visibility = System.Windows.Visibility.Visible;
                        liststring["硕士专业"] = true;
                        break;
                    case "博士毕业院校":
                        this.DGRole.Columns[21].Visibility = System.Windows.Visibility.Visible;
                        liststring["博士毕业院校"] = true;
                        break;

                    case "博士专业":
                        this.DGRole.Columns[22].Visibility = System.Windows.Visibility.Visible;
                        liststring["博士专业"] = true;
                        break;
                    case "学历":
                        this.DGRole.Columns[23].Visibility = System.Windows.Visibility.Visible;
                        liststring["学历"] = true;
                        break;
                    case "学位":
                        this.DGRole.Columns[24].Visibility = System.Windows.Visibility.Visible;
                        liststring["学位"] = true;
                        break;
                    case "联系方式/手机号码":
                        this.DGRole.Columns[25].Visibility = System.Windows.Visibility.Visible;
                        liststring["联系方式/手机号码"] = true;
                        break;
                    case "电子邮箱":
                        this.DGRole.Columns[26].Visibility = System.Windows.Visibility.Visible;
                        liststring["电子邮箱"] = true;
                        break;
                    case "健康程度":
                        this.DGRole.Columns[27].Visibility = System.Windows.Visibility.Visible;
                        liststring["健康程度"] = true;
                        break;
                    case "婚姻状况":
                        this.DGRole.Columns[28].Visibility = System.Windows.Visibility.Visible;
                        liststring["婚姻状况"] = true;
                        break;
                    case "通讯地址":
                        this.DGRole.Columns[29].Visibility = System.Windows.Visibility.Visible;
                        liststring["通讯地址"] = true;
                        break;
                }
            }
            else
            {
                switch (((CheckBox)sender).Content.ToString())
                {
                    case "面试日期":
                        this.DGRole.Columns[1].Visibility = System.Windows.Visibility.Visible;
                        liststring["面试日期"] = true;
                        break;
                    case "场次":
                        this.DGRole.Columns[2].Visibility = System.Windows.Visibility.Visible;
                        liststring["场次"] = true;
                        break;
                    case "面试时间":
                        this.DGRole.Columns[3].Visibility = System.Windows.Visibility.Visible;
                        liststring["面试时间"] = true;
                        break;
                    case "招录单位":
                        this.DGRole.Columns[4].Visibility = System.Windows.Visibility.Visible;
                        liststring["招录单位"] = true;
                        break;
                    case "报考职位":
                        this.DGRole.Columns[5].Visibility = System.Windows.Visibility.Visible;
                        liststring["报考职位"] = true;
                        break;
                    case "姓名":
                        this.DGRole.Columns[6].Visibility = System.Windows.Visibility.Visible;
                        liststring["姓名"] = true;
                        break;
                    case "笔试分数":
                        this.DGRole.Columns[7].Visibility = System.Windows.Visibility.Visible;
                        liststring["笔试分数"] = true;
                        break;

                    case "身份证号":
                        this.DGRole.Columns[8].Visibility = System.Windows.Visibility.Visible;
                        liststring["身份证号"] = true;
                        break;
                    case "现任单位":
                        this.DGRole.Columns[9].Visibility = System.Windows.Visibility.Visible;
                        liststring["现任单位"] = true;
                        break;
                    case "现任职务":
                        this.DGRole.Columns[10].Visibility = System.Windows.Visibility.Visible;
                        liststring["现任职务"] = true;
                        break;
                    case "现任职务层次":
                        this.DGRole.Columns[11].Visibility = System.Windows.Visibility.Visible;
                        liststring["现任职务层次"] = true;
                        break;
                    case "现任职务层次时间":
                        this.DGRole.Columns[12].Visibility = System.Windows.Visibility.Visible;
                        liststring["现任职务层次时间"] = true;
                        break;
                    case "性别":
                        this.DGRole.Columns[13].Visibility = System.Windows.Visibility.Visible;
                        liststring["性别"] = true;
                        break;
                    case "出生日期":
                        this.DGRole.Columns[14].Visibility = System.Windows.Visibility.Visible;
                        liststring["出生日期"] = true;
                        break;

                    case "政治面貌":
                        this.DGRole.Columns[15].Visibility = System.Windows.Visibility.Visible;
                        liststring["政治面貌"] = true;
                        break;
                    case "民族":
                        this.DGRole.Columns[16].Visibility = System.Windows.Visibility.Visible;
                        liststring["民族"] = true;
                        break;
                    case "本科毕业院校":
                        this.DGRole.Columns[17].Visibility = System.Windows.Visibility.Visible;
                        liststring["本科毕业院校"] = true;
                        break;
                    case "本科专业":
                        this.DGRole.Columns[18].Visibility = System.Windows.Visibility.Visible;
                        liststring["本科专业"] = true;
                        break;
                    case "硕士毕业院校":
                        this.DGRole.Columns[19].Visibility = System.Windows.Visibility.Visible;
                        liststring["硕士毕业院校"] = true;
                        break;
                    case "硕士专业":
                        this.DGRole.Columns[20].Visibility = System.Windows.Visibility.Visible;
                        liststring["硕士专业"] = true;
                        break;
                    case "博士毕业院校":
                        this.DGRole.Columns[21].Visibility = System.Windows.Visibility.Visible;
                        liststring["博士毕业院校"] = true;
                        break;

                    case "博士专业":
                        this.DGRole.Columns[22].Visibility = System.Windows.Visibility.Visible;
                        liststring["博士专业"] = true;
                        break;
                    case "学历":
                        this.DGRole.Columns[23].Visibility = System.Windows.Visibility.Visible;
                        liststring["学历"] = true;
                        break;
                    case "学位":
                        this.DGRole.Columns[24].Visibility = System.Windows.Visibility.Visible;
                        liststring["学位"] = true;
                        break;
                    case "联系方式/手机号码":
                        this.DGRole.Columns[25].Visibility = System.Windows.Visibility.Visible;
                        liststring["联系方式/手机号码"] = true;
                        break;
                    case "电子邮箱":
                        this.DGRole.Columns[26].Visibility = System.Windows.Visibility.Visible;
                        liststring["电子邮箱"] = true;
                        break;
                    case "健康程度":
                        this.DGRole.Columns[27].Visibility = System.Windows.Visibility.Visible;
                        liststring["健康程度"] = true;
                        break;
                    case "婚姻状况":
                        this.DGRole.Columns[28].Visibility = System.Windows.Visibility.Visible;
                        liststring["婚姻状况"] = true;
                        break;
                    case "通讯地址":
                        this.DGRole.Columns[29].Visibility = System.Windows.Visibility.Visible;
                        liststring["通讯地址"] = true;
                        break;
                }
            }
            

        }

        private void cbMonth_UnChecked(object sender, RoutedEventArgs e)
        {
            if (FBType == "选调交流")
            {
                this.DGRole.Columns[7].Visibility = System.Windows.Visibility.Collapsed;
                switch (((CheckBox)sender).Content.ToString())
                {
                    case "面试日期":
                        this.DGRole.Columns[1].Visibility = System.Windows.Visibility.Collapsed;
                        liststring["面试日期"] = false;
                        break;
                    case "场次":
                        this.DGRole.Columns[2].Visibility = System.Windows.Visibility.Collapsed;
                        liststring["场次"] = false;
                        break;
                    case "面试时间":
                        this.DGRole.Columns[3].Visibility = System.Windows.Visibility.Collapsed;
                        liststring["面试时间"] = false;
                        break;
                    case "招录单位":
                        this.DGRole.Columns[4].Visibility = System.Windows.Visibility.Collapsed;
                        liststring["招录单位"] = false;
                        break;
                    case "报考职位":
                        this.DGRole.Columns[5].Visibility = System.Windows.Visibility.Collapsed;
                        liststring["报考职位"] = false;
                        break;
                    case "姓名":
                        this.DGRole.Columns[6].Visibility = System.Windows.Visibility.Collapsed;
                        liststring["姓名"] = false;
                        break;
                    //case "笔试分数":
                    //    this.DGRole.Columns[7].Visibility = System.Windows.Visibility.Visible;
                    //    liststring["笔试分数"] = true;
                    //    break;

                    case "身份证号":
                        this.DGRole.Columns[8].Visibility = System.Windows.Visibility.Collapsed;
                        liststring["身份证号"] = false;
                        break;
                    case "现任单位":
                        this.DGRole.Columns[9].Visibility = System.Windows.Visibility.Collapsed;
                        liststring["现任单位"] = false;
                        break;
                    case "现任职务":
                        this.DGRole.Columns[10].Visibility = System.Windows.Visibility.Collapsed;
                        liststring["现任职务"] = false;
                        break;
                    case "现任职务层次":
                        this.DGRole.Columns[11].Visibility = System.Windows.Visibility.Collapsed;
                        liststring["现任职务层次"] = false;
                        break;
                    case "现任职务层次时间":
                        this.DGRole.Columns[12].Visibility = System.Windows.Visibility.Collapsed;
                        liststring["现任职务层次时间"] = false;
                        break;
                    case "性别":
                        this.DGRole.Columns[13].Visibility = System.Windows.Visibility.Collapsed;
                        liststring["性别"] = false;
                        break;
                    case "出生日期":
                        this.DGRole.Columns[14].Visibility = System.Windows.Visibility.Collapsed;
                        liststring["出生日期"] = false;
                        break;

                    case "政治面貌":
                        this.DGRole.Columns[15].Visibility = System.Windows.Visibility.Collapsed;
                        liststring["政治面貌"] = false;
                        break;
                    case "民族":
                        this.DGRole.Columns[16].Visibility = System.Windows.Visibility.Collapsed;
                        liststring["民族"] = false;
                        break;
                    case "本科毕业院校":
                        this.DGRole.Columns[17].Visibility = System.Windows.Visibility.Collapsed;
                        liststring["本科毕业院校"] = false;
                        break;
                    case "本科专业":
                        this.DGRole.Columns[18].Visibility = System.Windows.Visibility.Collapsed;
                        liststring["本科专业"] = false;
                        break;
                    case "硕士毕业院校":
                        this.DGRole.Columns[19].Visibility = System.Windows.Visibility.Collapsed;
                        liststring["硕士毕业院校"] = false;
                        break;
                    case "硕士专业":
                        this.DGRole.Columns[20].Visibility = System.Windows.Visibility.Collapsed;
                        liststring["硕士专业"] = false;
                        break;
                    case "博士毕业院校":
                        this.DGRole.Columns[21].Visibility = System.Windows.Visibility.Collapsed;
                        liststring["博士毕业院校"] = false;
                        break;

                    case "博士专业":
                        this.DGRole.Columns[22].Visibility = System.Windows.Visibility.Collapsed;
                        liststring["博士专业"] = false;
                        break;
                    case "学历":
                        this.DGRole.Columns[23].Visibility = System.Windows.Visibility.Collapsed;
                        liststring["学历"] = false;
                        break;
                    case "学位":
                        this.DGRole.Columns[24].Visibility = System.Windows.Visibility.Collapsed;
                        liststring["学位"] = false;
                        break;
                    case "联系方式/手机号码":
                        this.DGRole.Columns[25].Visibility = System.Windows.Visibility.Collapsed;
                        liststring["联系方式/手机号码"] = false;
                        break;
                    case "电子邮箱":
                        this.DGRole.Columns[26].Visibility = System.Windows.Visibility.Collapsed;
                        liststring["电子邮箱"] = false;
                        break;
                    case "健康程度":
                        this.DGRole.Columns[27].Visibility = System.Windows.Visibility.Collapsed;
                        liststring["健康程度"] = false;
                        break;
                    case "婚姻状况":
                        this.DGRole.Columns[28].Visibility = System.Windows.Visibility.Collapsed;
                        liststring["婚姻状况"] = false;
                        break;
                    case "通讯地址":
                        this.DGRole.Columns[29].Visibility = System.Windows.Visibility.Collapsed;
                        liststring["通讯地址"] = false;
                        break;
                }
            }
            else
            {
                //this.DGRole.Columns[7].Visibility = System.Windows.Visibility.Visible;
                switch (((CheckBox)sender).Content.ToString())
                {
                    case "面试日期":
                        this.DGRole.Columns[1].Visibility = System.Windows.Visibility.Collapsed;
                        liststring["面试日期"] = false;
                        break;
                    case "场次":
                        this.DGRole.Columns[2].Visibility = System.Windows.Visibility.Collapsed;
                        liststring["场次"] = false;
                        break;
                    case "面试时间":
                        this.DGRole.Columns[3].Visibility = System.Windows.Visibility.Collapsed;
                        liststring["面试时间"] = false;
                        break;
                    case "招录单位":
                        this.DGRole.Columns[4].Visibility = System.Windows.Visibility.Collapsed;
                        liststring["招录单位"] = false;
                        break;
                    case "报考职位":
                        this.DGRole.Columns[5].Visibility = System.Windows.Visibility.Collapsed;
                        liststring["报考职位"] = false;
                        break;
                    case "姓名":
                        this.DGRole.Columns[6].Visibility = System.Windows.Visibility.Collapsed;
                        liststring["姓名"] = false;
                        break;
                    case "笔试分数":
                        this.DGRole.Columns[7].Visibility = System.Windows.Visibility.Collapsed;
                        liststring["笔试分数"] = false;
                        break;

                    case "身份证号":
                        this.DGRole.Columns[8].Visibility = System.Windows.Visibility.Collapsed;
                        liststring["身份证号"] = false;
                        break;
                    case "现任单位":
                        this.DGRole.Columns[9].Visibility = System.Windows.Visibility.Collapsed;
                        liststring["现任单位"] = false;
                        break;
                    case "现任职务":
                        this.DGRole.Columns[10].Visibility = System.Windows.Visibility.Collapsed;
                        liststring["现任职务"] = false;
                        break;
                    case "现任职务层次":
                        this.DGRole.Columns[11].Visibility = System.Windows.Visibility.Collapsed;
                        liststring["现任职务层次"] = false;
                        break;
                    case "现任职务层次时间":
                        this.DGRole.Columns[12].Visibility = System.Windows.Visibility.Collapsed;
                        liststring["现任职务层次时间"] = false;
                        break;
                    case "性别":
                        this.DGRole.Columns[13].Visibility = System.Windows.Visibility.Collapsed;
                        liststring["性别"] = false;
                        break;
                    case "出生日期":
                        this.DGRole.Columns[14].Visibility = System.Windows.Visibility.Collapsed;
                        liststring["出生日期"] = false;
                        break;

                    case "政治面貌":
                        this.DGRole.Columns[15].Visibility = System.Windows.Visibility.Collapsed;
                        liststring["政治面貌"] = false;
                        break;
                    case "民族":
                        this.DGRole.Columns[16].Visibility = System.Windows.Visibility.Collapsed;
                        liststring["民族"] = false;
                        break;
                    case "本科毕业院校":
                        this.DGRole.Columns[17].Visibility = System.Windows.Visibility.Collapsed;
                        liststring["本科毕业院校"] = false;
                        break;
                    case "本科专业":
                        this.DGRole.Columns[18].Visibility = System.Windows.Visibility.Collapsed;
                        liststring["本科专业"] = false;
                        break;
                    case "硕士毕业院校":
                        this.DGRole.Columns[19].Visibility = System.Windows.Visibility.Collapsed;
                        liststring["硕士毕业院校"] = false;
                        break;
                    case "硕士专业":
                        this.DGRole.Columns[20].Visibility = System.Windows.Visibility.Collapsed;
                        liststring["硕士专业"] = false;
                        break;
                    case "博士毕业院校":
                        this.DGRole.Columns[21].Visibility = System.Windows.Visibility.Collapsed;
                        liststring["博士毕业院校"] = false;
                        break;

                    case "博士专业":
                        this.DGRole.Columns[22].Visibility = System.Windows.Visibility.Collapsed;
                        liststring["博士专业"] = false;
                        break;
                    case "学历":
                        this.DGRole.Columns[23].Visibility = System.Windows.Visibility.Collapsed;
                        liststring["学历"] = false;
                        break;
                    case "学位":
                        this.DGRole.Columns[24].Visibility = System.Windows.Visibility.Collapsed;
                        liststring["学位"] = false;
                        break;
                    case "联系方式/手机号码":
                        this.DGRole.Columns[25].Visibility = System.Windows.Visibility.Collapsed;
                        liststring["联系方式/手机号码"] = false;
                        break;
                    case "电子邮箱":
                        this.DGRole.Columns[26].Visibility = System.Windows.Visibility.Collapsed;
                        liststring["电子邮箱"] = false;
                        break;
                    case "健康程度":
                        this.DGRole.Columns[27].Visibility = System.Windows.Visibility.Collapsed;
                        liststring["健康程度"] = false;
                        break;
                    case "婚姻状况":
                        this.DGRole.Columns[28].Visibility = System.Windows.Visibility.Collapsed;
                        liststring["婚姻状况"] = false;
                        break;
                    case "通讯地址":
                        this.DGRole.Columns[29].Visibility = System.Windows.Visibility.Collapsed;
                        liststring["通讯地址"] = false;
                        break;
                }
            }
        }

        private void CheckBox_Checked(object sender, RoutedEventArgs e)
        {
            if (ListBoxOfLife != null)
            foreach (var item in ListBoxOfLife.Items)
            {
                ((System.Windows.Controls.Primitives.ToggleButton)(item)).IsChecked = true;
            }

        }

        private void chkHiddenCols_Unchecked(object sender, RoutedEventArgs e)
        {
            if (ListBoxOfLife != null)
            foreach (var item in ListBoxOfLife.Items)
            {
                ((System.Windows.Controls.Primitives.ToggleButton)(item)).IsChecked = false;
            }
        }

        void Client1_GetExcelFileCompleted(object sender, GetExcelFileCompletedEventArgs e)
        {
            List<byte> content = e.UserState as List<byte>;
            FileTransferStream fff = e.Result;
            if (fff.IsFinished == false)
            {
                content.AddRange(fff.FileContent);
                string username = Session.LoginUser.LoginName;
                Client1.GetExcelFileAsync(models, Session.LoginUser.LoginName, liststring, content);
            }
            else
            {
                content.AddRange(fff.FileContent);
                byte[] bytes = content.ToArray();
                ExportPersonnelInfo.Write(bytes, 0, bytes.Length);
                ExportPersonnelInfo.Close();
                ExportPersonnelInfo.Dispose();
                SilverlightMessageBoxLibrary.Message.InfoMessage("保存成功!");
            }
        }

        public void Load(int year, string FaBuType)
        {
            Client1.GetMianShiTongZhiBiaoCompleted -=
                new EventHandler<PublicOfficialSelectionService.GetMianShiTongZhiBiaoCompletedEventArgs>(Client1_GetMianShiTongZhiBiaoCompleted);
            Client1.GetMianShiTongZhiBiaoCompleted +=
                new EventHandler<PublicOfficialSelectionService.GetMianShiTongZhiBiaoCompletedEventArgs>(Client1_GetMianShiTongZhiBiaoCompleted);
            Client1.GetMianShiTongZhiBiaoAsync(year, FaBuType,"面试");

        }

        void Client1_GetMianShiTongZhiBiaoCompleted(object sender, PublicOfficialSelectionService.GetMianShiTongZhiBiaoCompletedEventArgs e)
        {
            DGRole.ItemsSource = e.Result;
            models = e.Result;

        }
        private Stream ExportPersonnelInfo = null;
        private void MianShiData_Click(object sender, RoutedEventArgs e)
        {
            #region excel模板方式，但是没法自定义导出字段
            if (models != null)
            {
                var downLoad = new SaveFileDialog()
                {
                    //Filter = "Excel files(2007~2010) (*.xlsx)|*.xlsx|Excel files(2003) (*.xls)|*.xls", //"Excel files (*.xlsx)|*.xlsx|(*.xls)|*.xls",
                    Filter = "Excel files(2003) (*.xls)|*.xls",
                };
                if (downLoad.ShowDialog() == true)
                {
                    ExportPersonnelInfo = downLoad.OpenFile();
                    List<byte> content = new List<byte>();
                    Client1.GetExcelFileAsync(models, Session.LoginUser.LoginName, liststring, content);
                }
            }
            #endregion
            //var downLoad = new SaveFileDialog()
            //{
            //    //Filter = "Excel files(2007~2010) (*.xlsx)|*.xlsx|Excel files(2003) (*.xls)|*.xls", //"Excel files (*.xlsx)|*.xlsx|(*.xls)|*.xls",
            //    Filter = "Excel files(2003) (*.xls)|*.xls",
            //};
            //if (downLoad.ShowDialog() == true)
            //{
            //    ExportPersonnelInfo = downLoad.OpenFile();
            //    XlsDocument xls = new XlsDocument();
            //    XF xf = xls.NewXF();
            //    xf.UseBorder = true;
            //    xf.TopLineStyle = 1;
            //    xf.TopLineColor = org.in2bits.MyXls.Colors.Black;
            //    xf.BottomLineStyle = 1;
            //    xf.BottomLineColor = org.in2bits.MyXls.Colors.Black;
            //    xf.LeftLineStyle = 1;
            //    xf.LeftLineColor = org.in2bits.MyXls.Colors.Black;
            //    xf.RightLineStyle = 1;
            //    xf.RightLineColor = org.in2bits.MyXls.Colors.Black;

            //    Worksheet sheet = xls.Workbook.Worksheets.AddNamed("面试人员信息");
            //    sheet.Cells.Add(1, 1, "序号", xf);
            //    if (liststring["面试组别"] == true) sheet.Cells.Add(1, 2, "面试组别", xf);
            //    sheet.Cells.Add(1, 3, "面试日期", xf);
            //    sheet.Cells.Add(1, 4, "用人单位", xf);
            //    sheet.Cells.Add(1, 5, "职位名称", xf);
            //    sheet.Cells.Add(1, 6, "姓名", xf);
            //    sheet.Cells.Add(1, 7, "笔试分数", xf);
            //    sheet.Cells.Add(1, 8, "分值折算40%", xf);
            //    sheet.Cells.Add(1, 9, "面试分数", xf);
            //    sheet.Cells.Add(1, 10, "分值折算60%", xf);
            //    sheet.Cells.Add(1, 11, "考生总分", xf);
            //    sheet.Cells.Add(1, 12, "名次", xf);
            //    sheet.Cells.Add(1, 13, "备注", xf);
            //}
        }

        /// <summary>
        /// 导出面试通知
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private WordActionService.WordActionClient _client = null;
        private void ExportInterview_Click(object sender, RoutedEventArgs e)
        {
            if (DGRole.SelectedItem != null )
            {
                if (_client == null)
                {
                    _client = new WordActionService.WordActionClient();
                    _client.ExportInterviewInfoCompleted += (sender1, e1) =>
                    {
                        //保存结果
                        if (e1.Error == null)
                        {
                            string serverpath = _client.InnerChannel.Via.AbsoluteUri.Replace(_client.InnerChannel.Via.AbsolutePath, "");
                            System.Windows.Browser.HtmlPage.Window.Navigate(new Uri(serverpath + e1.Result, UriKind.RelativeOrAbsolute));
                        }
                        else
                        {
                            SilverlightMessageBoxLibrary.Message.ErrorMessage("导出失败,可能原因:\n" + e1.Error);
                        }
                    };
                }
                foreach (var item in DGRole.SelectedItems)
                {
                    var entity = item as PublicOfficialRecordModel;
                    DateTime dt = (DateTime)entity.RiQi;
                    string dayOfWeek = null;
                    switch (dt.DayOfWeek)
                    {
                        case DayOfWeek.Monday: 
                            dayOfWeek = "周一";
                            break;
                        case DayOfWeek.Tuesday:
                            dayOfWeek = "周二";
                            break;
                        case DayOfWeek.Wednesday:
                            dayOfWeek = "周三";
                            break;
                        case DayOfWeek.Thursday:
                            dayOfWeek = "周四";
                            break;
                        case DayOfWeek.Friday:
                            dayOfWeek = "周五";
                            break;
                        case DayOfWeek.Saturday:
                            dayOfWeek = "周六";
                            break;
                        case DayOfWeek.Sunday:
                            dayOfWeek = "周七";
                            break;

                    }
                    int hour = int.Parse( entity.Shi.Split(':')[0]);//DateTime.Parse(entity.Shi);
                    _client.ExportInterviewInfoAsync(new ObservableCollection<string>(){entity.EmpName, 

                    string.Format("{0}月 {1} 日（{2}）{3}{4}：{5}", dt.Month, dt.Day, 
                    dayOfWeek, hour >12? "下午" :"上午",  hour >12? "12" :"8", 
                     hour >12? "30" :"00" ),entity.MianShiDiZhi}, 0); //上午8 点， 下午 12：30
                    System.Threading.Thread.Sleep(new TimeSpan(0,0,0,1,0));
                }
                //_client.ExportInterviewInfoAsync(new System.Collections.ObjectModel.ObservableCollection<string>() { entity., "3月 12 日（周一）上午8：00", "徐汇区委党校（上海市徐汇区钦州南路567号）二楼218会议室" }, 1);
            }
            else
            {
                SilverlightMessageBoxLibrary.Message.InfoMessage("请至少选中一条记录");
            }
        }
    }
}